手機 APP 推播方案
昨天我們講過,推播的機制應該是怎麼樣的.一開始我們就會需要跟 APNS 要求 Token ,所以我們在應用程式啓動的時候,如果還沒有拿到 Token ,必須跟 APNS 取得 Token
- (BOOL)application:(UIApplication *)application
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    // Register for push notifications
    [application registerForRemoteNotificationTypes: 
                                 UIRemoteNotificationTypeBadge |
                                 UIRemoteNotificationTypeAlert |             
                                 UIRemoteNotificationTypeSound];
    ...
}
這是向 APNS 要求 Token
而 APNS 處理完成之後,在 AppDelegate 當中會有事件被啓動,是取得了遠方 Token
- (void)application:(UIApplication *)application 
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:newDeviceToken];
    [currentInstallation saveInBackground];
}
取得了之後我們再進行處理即可